var t = getApp(), a = require("../../utils/util.js"), e = null, s = null, n = "", o = !1, i = 0, r = wx.createInnerAudioContext();

r.src = "/voice/1.mp3";

var c = null, u = null;

Page({
    data: {
        StatusBar: t.globalData.StatusBar,
        gzAd_01: t.ad.gzAd_01,
        videoAdLoading: !1,
        shaking: !1,
        allowShaking: !0,
        y: -170,
        modalName: "",
        colors: [ "green", "red", "black", "blue" ],
        backgrounds: [ "bg1", "bg2", "bg3", "bg4", "bg5", "bg6" ],
        canUserSetGailv: !1,
        status: {
            voice: !0,
            curColor: 3,
            curGailv: 1,
            curBackground: 0,
            accelerometer: !0,
            max: 5,
            num: 5,
            autoOpen: !1,
            opacity: !1,
            vibrate: !1,
            locations: [ 1, 1, 1, 1, 1, 1 ],
            shaizis: [ "one", "two", "three", "four", "five", "six" ],
            model: "pillars"
        },
        productImg: [ "/image/tg/01.png", "/image/tg/02.png" ]
    },
    videoAdShow: function() {
        var t = this;
        null != e && e.show().catch(function() {
            t.setData({
                videoAdLoading: !1
            }), e.load().then(function() {
                return e.show();
            }).catch(function(t) {
                a.videoAdErrCodeHandle(t);
            });
        });
    },
    onShareAppMessage: function(t) {
        return {
            title: "KTV喝酒摇骰子",
            path: "/pages/index/index?id=" + n,
            imageUrl: "../../image/aa.jpg"
        };
    },
    onLoad: function(t) {
        null != t.id && (n = t.id);
        var a = new Date().valueOf() / 1e3, e = wx.getStorageSync("ti1");
        a - e > 600 ? (wx.createInterstitialAd && ((u = wx.createInterstitialAd({
            adUnitId: "adunit-b5abd8d44c947f4d"
        })).onLoad(function() {
            var t = new Date().valueOf() / 1e3;
            wx.setStorage({
                key: "ti1",
                data: t
            });
        }), u.onError(function(t) {}), u.onClose(function() {})), setTimeout(function() {
            u.show().catch(function(t) {
                console.error(t);
            });
        }, 500)) : "" == e && (wx.createInterstitialAd && ((u = wx.createInterstitialAd({
            adUnitId: "adunit-b5abd8d44c947f4d"
        })).onLoad(function() {
            var t = new Date().valueOf() / 1e3;
            wx.setStorage({
                key: "ti1",
                data: t
            });
        }), u.onError(function(t) {}), u.onClose(function() {})), setTimeout(function() {
            u.show().catch(function(t) {
                console.error(t);
            });
        }, 500));
    },
    videoAdLoad: function() {
        var a = this;
        if (1 != this.data.videoAdLoading) return null != e ? (this.setData({
            videoAdLoading: !0
        }), this.videoAdShow(1)) : void (wx.createRewardedVideoAd && (this.setData({
            videoAdLoading: !0
        }), (e = wx.createRewardedVideoAd({
            adUnitId: t.ad.jlAd_01,
            multiton: !0
        })).onLoad(function() {
            1 == a.data.videoAdLoading && a.videoAdShow();
        }), e.onError(function(t) {
            e = null, a.setData({
                videoAdLoading: !1
            });
        }), e.onClose(function(t) {
            a.setData({
                videoAdLoading: !1
            }), t && t.isEnded && (a.canUserSetGailvHandle() ? a.setData({
                "status.max": 10,
                "status.curGailv": 7
            }) : a.setData({
                canUserSetGailv: !0,
                "status.curGailv": 3
            }), wx.setStorageSync("statusCache", a.data.status), wx.setStorageSync("canUserSetGailv", {
                canUserSetGailv: !0,
                time: Date.parse(new Date())
            }));
        })));
    },
    canUserSetGailvHandle: function() {
        try {
            var t = wx.getStorageSync("canUserSetGailv");
            return "" != t && (Date.parse(new Date()) - t.time) / 1e3 < 43200;
        } catch (t) {}
        return !1;
    },
    setCurColor: function() {
        var t = Math.floor(4 * Math.random()) + 1;
        switch (n) {
          case "1":
          case "2":
          case "3":
          case "4":
            t = Number(n);
            break;

          case "wlx":
          case "w2":
            t = 3;
        }
        this.setData({
            "status.curColor": t
        }), wx.setStorageSync("statusCache", this.data.status);
    },
    onHide: function() {
        o = !1, wx.stopAccelerometer(), null != c && clearInterval(c);
    },
    onUnload: function() {
        o = !1, wx.stopAccelerometer(), null != c && clearInterval(c);
    },
    onShow: function() {
        o = !0, "function" == typeof this.getTabBar && this.getTabBar() && this.getTabBar().setData({
            selected: 1
        });
        try {
            wx.getStorageSync("statusCache");
        } catch (t) {}
        this.canUserSetGailvHandle() ? this.setData({
            canUserSetGailv: !0
        }) : this.setData({
            "status.curGailv": 1,
            "status.max": 5,
            "status.opacity": !1
        }), this.data.status.accelerometer && this.accelerometer();
    },
    accelerometer: function() {
        var t = this;
        wx.onAccelerometerChange(function(a) {
            !t.data.shaking && o && Math.abs(a.x) > .8 && Math.abs(a.y) > .8 && Math.abs(a.z) > .8 && (t.change(), 
            wx.vibrateLong());
        });
    },
    shaizisSort: function() {
        var t = this.data.status.shaizis.sort(function() {
            return .5 - Math.random();
        });
        this.setData({
            "status.shaizis": t
        });
    },
    allow: function() {
        this.data.shaking || this.setData({
            allowShaking: !this.data.allowShaking
        });
    },
    arrayRand: function(t) {
        var a = t.length;
        return t[Math.floor(Math.random() * a)];
    },
    change: function(e) {
        if (!this.data.shaking && this.data.allowShaking) {
            var n = this;
            n.setData({
                shaking: !0,
                y: 0
            }), n.data.status.voice && (r.startTime = 0, r.play()), n.data.status.vibrate && wx.vibrateLong(), 
            c = setInterval(function() {
                n.shaizisSort();
            }, 500), setTimeout(function() {
                r.stop();
                var e = .01 - Math.random() > 0 ? "pillars" : "normal";
                if ("pillars" == e) {
                    n.setData({
                        "status.shaizis": [ "one", "two", "three", "four", "five", "six" ]
                    });
                    var o = [ 1, 1, 1, 1, 1, 1 ];
                } else {
                    var u = !1;
                    n.data.status.curGailv > 1 && (u = n.data.status.curGailv / 100 - Math.random() > 0 && n.arrayRand([ 1, 2, 3, 4, 5, 6 ])), 
                    o = [];
                    for (var d = 0; d <= 6; d++) 0 != u ? o.push(n.arrayRand([ 1, u ])) : o.push(n.arrayRand([ 1, 2, 3, 4, 5, 6 ]));
                }
                null != c && clearInterval(c), n.setData({
                    "status.locations": o,
                    "status.model": e,
                    shaking: !1
                }), wx.setStorageSync("statusCache", n.data.status), n.data.status.autoOpen && setTimeout(function() {
                    n.setData({
                        y: -500
                    });
                }, 500), a.setHistory(n.data.status), 4 == ++i ? wx.createInterstitialAd && ((s = wx.createInterstitialAd({
                    adUnitId: t.ad.cpAd_01
                })).onLoad(function() {}), s.onError(function(t) {}), s.onClose(function() {})) : 5 != i && 20 != i && 40 != i && 75 != i || s && "function" == typeof s.show && s.show().catch(function(t) {
                    console.info(t);
                });
            }, 1500);
        }
    },
    numChange: function(t) {
        var a = this.data.status.num;
        switch (t.currentTarget.dataset.type) {
          case "+":
            a >= 6 ? a = 6 : a++;
            break;

          case "-":
            a <= 1 ? a = 1 : a--;
        }
        this.setData({
            "status.num": a
        });
    },
    colorChange: function(t) {
        var a = Number(t.currentTarget.dataset.color);
        a = a > 4 ? 1 : a, this.setData({
            "status.curColor": a
        }), wx.setStorageSync("statusCache", this.data.status);
    },
    backgroundChange: function(t) {
        var a = Number(t.currentTarget.dataset.item);
        a = a > 5 ? 0 : a, this.setData({
            "status.curBackground": a
        }), wx.setStorageSync("statusCache", this.data.status);
    },
    gailvChange: function(t) {
        this.setData({
            "status.curGailv": t.detail.value
        });
    },
    voiceChange: function(t) {
        this.setData({
            "status.voice": !this.data.status.voice
        }), wx.setStorageSync("statusCache", this.data.status);
    },
    accelerometerChange: function(t) {
        this.setData({
            "status.accelerometer": !this.data.status.accelerometer
        }), this.data.status.accelerometer ? this.accelerometer() : wx.stopAccelerometer(), 
        wx.setStorageSync("statusCache", this.data.status);
    },
    autoOpenChange: function(t) {
        this.setData({
            "status.autoOpen": !this.data.status.autoOpen
        });
    },
    vibrateChange: function(t) {
        this.setData({
            "status.vibrate": !this.data.status.vibrate
        });
    },
    opacityChange: function(t) {
        var a = this;
        a.data.canUserSetGailv ? a.setData({
            "status.opacity": !a.data.status.opacity
        }) : wx.showModal({
            title: "透视眼功能",
            content: "需要观看广告后才可以设置哦\n\r\n\r😍 怎么这么帅 😍\n\r😍 太帅了 😍\n\r😍 帅 😍\n\r😍",
            confirmText: a.data.videoAdLoading ? "加载中" : "立即观看",
            showCancel: !a.data.videoAdLoading,
            cancelText: "取消",
            success: function(t) {
                t.confirm && a.videoAdLoad();
            }
        });
    },
    showModal: function(t) {
        this.setData({
            modalName: t.currentTarget.dataset.target
        });
    },
    hideModal: function() {
        wx.setStorageSync("statusCache", this.data.status), this.setData({
            modalName: null
        });
    },
    catchtap: function() {}
});